package com.lenovo.lcdm.dcm.controller;

import com.lenovo.lcdm.common.model.ResponseVo;
import com.lenovo.lcdm.dcm.dto.AttachmentDto;
import com.lenovo.lcdm.dcm.service.DcmAttachmentLinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @Auther xujing30
 * @Date 2024/01/26
 * @Description
 */
@RestController
public class DcmAttachmentController {

    @Autowired
    private DcmAttachmentLinkService attachmentLinkService;

    @PostMapping("/attachment/upload")
    @ResponseBody
    public ResponseVo uploadAttachment(AttachmentDto attachmentDto) throws IOException {
        ResponseVo responseVo = new ResponseVo();
        attachmentLinkService.uploadAttachment(attachmentDto);
        return responseVo;
    }

    @GetMapping("/attachment/download")
    public ResponseVo<String> downloadAttachment(@RequestParam(name = "attachmentId") String attachmentId) throws IOException {
        ResponseVo<String> responseVo = new ResponseVo();
        String url = attachmentLinkService.downloadAttachment(attachmentId);
        responseVo.setData(url);
        return responseVo;
    }
}
